<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script type="text/javascript" src="scripts/boot.js"></script>
<style type="text/css">
	body{
        margin:0;padding:0;border:0;width:100%;height:100%;overflow:hidden;
    }
</style>
</head>
<body>
	<div class="mini-toolbar" style="text-align:center;line-height:30px;" borderStyle="border:0;">
          <label >药品名称：</label>
          <input id="med_name" class="mini-textbox" style="width:120px;" onenter="onKeyEnter"/>
<!--           <label >药品类别：</label> -->
<!--           <input id="name" class="mini-textbox" style="width:120px;" onenter="onKeyEnter"/> -->
<!--           <br /> -->
          <label>产品/赠品/搭销：</label>
          <input id="med_type" class="mini-combobox" textField="keyValue" valueField="keyName" style="width:120px;" onenter="onKeyEnter"
          	url="dictionary_wm_key_val_view.do?typeName=MEDICINE_TYPE"/>
          <a class="mini-button" style="width:60px;" onclick="search()">查询</a>
    </div>
    <div class="mini-fit">
        <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" idField="id" allowResize="false"
            borderStyle="border-left:0;border-right:0;" onrowdblclick="onRowDblClick" url="orders_product_select_view.do">
            <div property="columns">
                <div type="indexcolumn" ></div>
                <div field="name" width="70%" headerAlign="center">药品名称</div>    
                <div field="medicineTypeName" width="30%" headerAlign="center" align="center">药品类型</div>                                          
                <div field="inventory" width="30%" headerAlign="center" align="center">总库存量</div>                                        
            </div>
        </div>
    </div>                
    <div class="mini-toolbar" style="text-align:center;padding-top:8px;padding-bottom:8px;" borderStyle="border:0;">
        <a class="mini-button" style="width:60px;" onclick="onOk()">确定</a>
        <span style="display:inline-block;width:25px;"></span>
        <a class="mini-button" style="width:60px;" onclick="onCancel()">取消</a>
    </div>
    <input class="mini-hidden" name="ordersId" />
    
<script type="text/javascript">
	mini.parse();
	var grid = mini.get("datagrid1");
	grid.load();
	
	var ordersId = mini.getbyName("ordersId");
	function SetData(data) {
		data = mini.clone(data);
		ordersId.setValue(data.ordersId);
	}
	
 	function GetData() {
        var row = grid.getSelected();
        return row;
    }
 	
    function search() {
        var medName = mini.get("med_name").getValue();
        var medType = mini.get("med_type").getValue();
        grid.load({ medName: medName, medType: medType });
    }
    
    function onKeyEnter(e) {
        search();
    }
    
    function onRowDblClick(e) {
        onOk();
    }
	    
    function CloseWindow(action) {
        if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
        else window.close();
    }

    function onOk() {
    	var row = grid.getSelected();
    	if(row) {
	    	$.post("orders_product_valid_exist.do", {ordersId: ordersId.getValue(), medicineId: row.id}, function(data) {
	    		if(data.flag) {
			        CloseWindow("ok");
	    		} else {
	    			mini.alert("该产品已选择，请选择其他产品！");
	    		}
	    	}, "json");
    	} else {
    		mini.alert("未选择任何产品！");
    	}
    }
    
    function onCancel() {
        CloseWindow("cancel");
    }
	    
</script>
</body>
</html>